package graph_viewer.gui;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

import java.util.*;
import java.io.*;

import graph_viewer.drawer.*;
import graph_viewer.util.*;

public abstract class App_Frame extends JFrame{
	protected void add_component(JFrame a_jframe, Component a_gui_component ){
		a_jframe.getContentPane().add( a_gui_component );
	}
	
	//@param position valid postion name. such as "South", "Center"
	protected void add_component(JFrame a_jframe, String position, Component a_gui_component ){
		a_jframe.getContentPane().add( position, a_gui_component );
	}

	protected JRadioButton[] build_JRadioButtons( String[] radio_names ){
		int number_of_radio	= radio_names.length;
		
		JRadioButton[] JRadioButtons	= new JRadioButton[ number_of_radio ];

		for ( int i = 0 ; i < number_of_radio; i++){
			JRadioButtons[i]	= new JRadioButton( radio_names[i] );
					
			JRadioButtons[i].setMnemonic(KeyEvent.VK_B);
			JRadioButtons[i].setActionCommand( radio_names[i] );
		}

		return JRadioButtons;	
	}

	protected void add_JRadioButtons( Container container, JRadioButton[] JRadioButtons){
		int number_of_radio	= JRadioButtons.length;
		
		for ( int i = 0 ; i < number_of_radio; i++){
			container.add( JRadioButtons[i] );
			
		}
	}

	protected ButtonGroup build_ButtonGroup( JRadioButton[] JRadioButtons , String selected_button_label ) {
		int number_of_radio	= JRadioButtons.length;

		ButtonGroup group = new ButtonGroup();
		for ( int i = 0 ; i < number_of_radio; i++ ){
			if ( JRadioButtons[i].getActionCommand().equals( selected_button_label ) ){
				JRadioButtons[i].setSelected( true );
			}
			group.add( JRadioButtons[i] );
		}

		return group;
	} 

	protected AbstractButton get_button_group_selected_item( ButtonGroup a_ButtonGroup ){
		AbstractButton	selected_button	= null;
		Enumeration		buttons			=  a_ButtonGroup.getElements();

		while( buttons.hasMoreElements() ){
			AbstractButton	a_button = (AbstractButton)buttons.nextElement();

			if ( a_button.isSelected() ){
				selected_button	= a_button;
			}
		}

		return selected_button;
	}
}